package com.insmess.speech.common.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 数字逆化处理工具类(写到一半写不下去了)
 */
public class NumberReverseUtils {
    //常见的跟在数字后面的单位
    private static final String COMMON_UNITS = "个只分万亿秒";
    //以空格分隔开的常用语，如成语、日常短语，用于避免误转
    private static final List<String> IDIOMS = new ArrayList<>();

    //总模式，筛选出可能需要替换的内容
    private static final Pattern PATTERN = Pattern.compile("");
    //细分匹配不同的数字类型
    //纯数字序号
    private static final Pattern PURE_NUM = Pattern.compile("[零幺一二三四五六七八九]+(点[零幺一二三四五六七八九]+)* *[a-zA-Z" + COMMON_UNITS + "]?");
    //数值
    private static final Pattern VALUE_NUM = Pattern.compile("十?(零?[一二两三四五六七八九十][十百千万]{1,2})*零?[一二三四五六七八九]?(点[零一二三四五六七八九]+)? *[a-zA-Z" + COMMON_UNITS + "]?");
//    //百分值
//    private static final Pattern PERCENT_VALUE = Pattern.compile("(?<![一二三四五六七八九])(百分之)[零一二三四五六七八九十百千万]+(点)?(?(2)[零一二三四五六七八九]+)");
//    //分数
//    private static final Pattern FRACTION_VALUE = Pattern.compile("([零一二三四五六七八九十百千万]+(点)?(?(2)[零一二三四五六七八九]+))分之([零一二三四五六七八九十百千万]+(点)?(?(4)[零一二三四五六七八九]+))");
//    //比值
//    private static final Pattern RATIO_VALUE = Pattern.compile("([零一二三四五六七八九十百千万]+(点)?(?(2)[零一二三四五六七八九]+))比([零一二三四五六七八九十百千万]+(点)?(?(4)[零一二三四五六七八九]+))");
//    //时间
//    private static final Pattern TIME_VALUE = Pattern.compile("[零一二三四五六七八九十]+点([零一二三四五六七八九十]+分)([零一二三四五六七八九十]+秒)?");
    //日期
    private static final Pattern DATE_VALUE = Pattern.compile("(?ix)" +
            "([零一二三四五六七八九]+年)([一二三四五六七八九十]+月([一二三四五六七八九十]+[日号]))|" +
            "(([零一二三四五六七八九]+年)([一二三四五六七八九十]+月))|" +
            "([一二三四五六七八九十]+月([一二三四五六七八九十]+[日号]))|" +
            "([零一二三四五六七八九]+年)");
    //中文数字对阿拉伯数字的映射
    private static final Map<String, String> NUM_MAPPER = new HashMap<>();
    //中文数字对数值的映射
    private static final Map<String, String> VALUE_MAPPER = new HashMap<>();

    static {
        IDIOMS.add("正经八百");
        //初始化
        NUM_MAPPER.put("零", "0");
        NUM_MAPPER.put("一", "1");
        NUM_MAPPER.put("幺", "1");
        NUM_MAPPER.put("二", "2");
        NUM_MAPPER.put("两", "2");
        NUM_MAPPER.put("三", "3");
        NUM_MAPPER.put("四", "4");
        NUM_MAPPER.put("五", "5");
        NUM_MAPPER.put("六", "6");
        NUM_MAPPER.put("七", "7");
        NUM_MAPPER.put("八", "8");
        NUM_MAPPER.put("九", "9");
        NUM_MAPPER.put("点", ".");
        VALUE_MAPPER.put("零", "0");
        VALUE_MAPPER.put("一", "1");
        VALUE_MAPPER.put("二", "2");
        VALUE_MAPPER.put("两", "2");
        VALUE_MAPPER.put("三", "3");
        VALUE_MAPPER.put("四", "4");
        VALUE_MAPPER.put("五", "5");
        VALUE_MAPPER.put("六", "6");
        VALUE_MAPPER.put("七", "7");
        VALUE_MAPPER.put("八", "8");
        VALUE_MAPPER.put("九", "9");
        VALUE_MAPPER.put("十", "10");
        VALUE_MAPPER.put("百", "100");
        VALUE_MAPPER.put("千", "1000");
        VALUE_MAPPER.put("万", "10000");
    }

    public static void main(String[] args) {
//        Pattern pattern = Pattern.compile("[一二]百");
        Pattern numPattern = Pattern.compile("十?(零?[一二两三四五六七八九十][十百千万]{1,2})*零?[一二三四五六七八九]?(点[零一二三四五六七八九]+)? *[a-zA-Z" + COMMON_UNITS + "]?");
        Matcher matcher = numPattern.matcher("我今天花了二百块去吃了一百三十八个烧鸡");
        if (matcher.find()) {
            String group = matcher.group();
            System.out.println(group);
        }
    }
}
